package com.lgr.store.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lgr.store.dao.MaterialDAO;
import com.lgr.store.utils.PageObject;
import com.lgr.store.vo.MaterialTypeVo;
import com.lgr.store.vo.MaterialVo;
import com.lgr.store.vo.ProdTypeVo;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MaterialService {
    @Resource
    MaterialDAO materialDAO;

    //列表
    @Transactional
    public List<MaterialVo> list(MaterialVo material, PageObject pager){
        List<MaterialVo> materialList = materialDAO.listAll(material,pager);
        return materialList;
    }
    //通过id查找数据
    @Transactional
    public MaterialVo getById(int materialId){
        return materialDAO.getById(materialId);
    }
    //新增
    @Transactional
    public void add(MaterialVo material){
        materialDAO.add(material);
    }
    //修改
    @Transactional
    public void update(MaterialVo material){
        materialDAO.update(material);
    }
    //新增or修改
    @Transactional
    public void saveOrUpdate(MaterialVo material){
        if(material.getMaterialId()==null){
            add(material);
        }else{
            update(material);
        }
    }
    //记录数
    @Transactional
    public int materialCount(){
        return materialDAO.materialCount();
    }
    //删除
    @Transactional
    public void materialDel(int materialId){
         materialDAO.materialDel(materialId);
    }
    //物料类别表
    @Transactional
    public List<MaterialTypeVo> materialTypeList(){
        List<MaterialTypeVo> mtList=materialDAO.materialTypeList();
        return mtList;
    }
    //物料类别表
    @Transactional
    public List<ProdTypeVo> prodList(){
        List<ProdTypeVo> pList=materialDAO.prodList();
        return pList;
    }
    
}
